﻿using System.Web.Mvc;
using System.Text;
using System;
using CodeFinder.Web.Models;

namespace CodeFinder.Web.Helper {
    public static class PagingHelpers {
        public static MvcHtmlString PageLinks (this HtmlHelper html, PageInfo pagingInfo, Func<int, string> pageUrl) {
            StringBuilder result = new StringBuilder();
            for (int i = 1;i <= pagingInfo.TotalPages;i++) {
                TagBuilder tag = new TagBuilder("a"); // Construct an <a> tag
                tag.MergeAttribute("href", pageUrl(i));
                tag.InnerHtml = i.ToString();
                if (i == pagingInfo.Current)
                    tag.AddCssClass("selected");
                result.Append(tag.ToString());
            }
            return MvcHtmlString.Create(result.ToString());
        }
    }
}